#########################################
# json
########################################

import json
from functools import reduce


class JsonTest():

    def f(self, a):
        return a * 2


if __name__ == '__main__':
    data = {
        'a': 1,
        'b': 2
    }

    ## lambda 函数
    f1 = lambda x: x * 2
    print(f1(1))

    f2 = lambda x, y, z: x + y + z
    print(f2(1, 2, 3))

    jt = JsonTest()
    ## map 函数
    items = [1, 2, 3, 4]
    print(list(map(jt.f, items)))

    print(list(map(lambda x: x * 3, items)))

    ## reduce
    result = reduce(lambda x, y: x + y, range(1, 5))
    print('result=', result)

    result1 = reduce(lambda x, y: x + y, ['h', 'e', 'l', 'l', 'o'])
    print('result1=', result1)

    ## filter 过滤
    print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5])))
